import java.util.LinkedList;

/**
 * linkedList双向链表
 */
public class LinkedListDemo {
    public static void main(String[] args) {
        //linkedlist就是栈和队列的合体
        LinkedList<String> stack = new LinkedList<>();
        stack.addFirst("first");//压栈
        stack.addFirst("second");
        stack.addFirst("third");
        System.out.println(stack);

        //弹栈
        System.out.println(stack.removeFirst());
        System.out.println(stack.removeFirst());
        System.out.println(stack.removeFirst());
        //压栈和弹栈,可以用push和pop代替

        //队列,入队
        LinkedList<String> queue = new LinkedList<>();
        queue.addLast("榜一");
        queue.addLast("榜二");
        queue.addLast("榜三");
        queue.addLast("榜四");
        System.out.println(queue);

        //出队
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());
    }
}
